<?php 
## include required files
/*******************************/
require_once '../../includefiles.php';
require_once '../../model/users.php';
include_once("../../model/trade.php");
include_once("../../model/state.php");
include_once("../../model/budget.php");
include_once("../../model/leads.php");
require_once '../../model/membershipplan.php';
require_once '../../redirect.php';

/*if($_SESSION['getbids_id']=='')
{	
	@header("location:".SITE_URL."/signin/");
	exit;
}*/
if($_SESSION['user_type'] == '3')
{
	@header("location:".SITE_URL."/");
	exit;
}

## creating objects of required models
$userObj 		= new Model_Users();
$tradeObj = new Model_TRADE();
$stateObj = new Model_State();
$budgetObj = new Model_Budget();
$leadObj = new Model_Leads();
$objPlan = new Model_PLAN();

/*===========================================================================*/
$userId =$_SESSION['getbids_id'];
if($userId!='')
{
	$userDetArray = $userObj->getUserDetailsByUserId($userId);
	$smarty->assign("userDetArray", $userDetArray);	
	
	$job_id = base64_decode($_GET['id1']);	
	
	$getuserjobviewArr = $userObj->getUserViewjobDetailsByUserIdJobId($userId,$job_id);
	$smarty->assign('getuserjobviewArr',$getuserjobviewArr);

}
/*===========================================================================*/	


if($_GET['id1'] !='')
{
	$job_id = base64_decode($_GET['id1']);	
	$getjobdetail =$userObj->getJobDetailsById($job_id);
	//echo "<pre>"; print_r($getjobdetail); exit;
	if($getjobdetail['trade_id']!='')
	{
		$getTradecat = $tradeObj->getTradeCategoryDetailsById($getjobdetail['trade_id']);	
		$getjobdetail['trade_name'] = $getTradecat['trade_category'];
	}
	
	if($getjobdetail['area']!='')
	{
		$getpostaldetail = $stateObj->getPostalCodeDetailsByPostalId($getjobdetail['area']);
		$getjobdetail['suburbname'] = $getpostaldetail['state'];
	}
	
	if($getpostaldetail['state']!='')
	{
		$getstatedetail = $stateObj->getStateDetailsByISOCODE($getpostaldetail['state']);
		$getjobdetail['statename'] = $getstatedetail['state_name'];
	}
	
	if($getjobdetail['approx_budget']!='')
	{
		$getbudgetdetail = $budgetObj->getBudgetDetailsById($getjobdetail['approx_budget']);
		$getjobdetail['budgetname'] = $getbudgetdetail['budget_name'];
	}
	
	$posted_date = ago($getjobdetail['date_added']);
	$getjobdetail['posted_date'] = $posted_date;
	
	if($getjobdetail['user_id']!='')
	{
		$postuserdetail = $userObj->getUserDetailsByUserId($getjobdetail['user_id']);
		$getjobdetail['username'] = $postuserdetail['first_name'].' '.$postuserdetail['last_name'];
	}
	
	
	
	$subject= "Hey, let everyone know that ".substr_replace($getjobdetail['job_desc'],"",40)."";

	$siteUrl= SITE_URL."/jobs/".base64_encode($getjobdetail['postjob_id'])."/findjobdetail/";
	
	$body= "Hi, Check this job out: ".$siteUrl."";
	
	$sendmail= "mailto:?subject=".$subject."&body=".$body;
	$getjobdetail['mailicon'] =$sendmail;
	
	// Twitter code
	$linkForTwitter='http://twitter.com/home?status='.$body; 
	$linkForTwitter=addslashes($linkForTwitter);
	$getjobdetail['linkForTwitter'] =$linkForTwitter;
	
	$smarty->assign('job_details', $getjobdetail);
	
	//code for lead price
	if($getjobdetail['area']!='' && $getjobdetail['jobtype_id']!='' && $getjobdetail['approx_budget']!='')
	{
		$getleadprice =	$leadObj->getLeadPriceByAreaJobTypeBudget($getjobdetail['area'],$getjobdetail['jobtype_id'],$getjobdetail['approx_budget']);
		//echo "<pre>"; print_r($getleadprice); exit;
		if($getleadprice['price']=='')
			$getleadprice['price'] = 10;
	}
	else
	{
			$getleadprice['price'] = 10;	
	}
	
	$smarty->assign('getleadprice',$getleadprice);
}

$getallTradeCat = $tradeObj->getAllTradesCategoryWithActiveStatus();
$i=0;
foreach($getallTradeCat as $newgetallTradeCat)
{
	$new_tradename =str_replace(" ","-",$newgetallTradeCat['trade_category']);	
	$getallTradeCat[$i]['new_tradename'] =str_replace("&","and",$new_tradename);	
	$i++;
}
$smarty->assign("getallTradeCat", $getallTradeCat);

$getallTradeJobType = $tradeObj->getAllJobTypeWithActiveStatus();
$i=0;
foreach($getallTradeJobType as $newgetallTradeJobType)
{
	$new_tradename =str_replace(" ","-",$newgetallTradeJobType['trade_category']);	
	$getallTradeJobType[$i]['new_jobtypename'] = str_replace("&","and",strtolower($new_tradename));	
	$i++;
}
$smarty->assign("getallTradeJobType", $getallTradeJobType);	

$getplandetail = $objPlan->getAllPlanInstedOfFree();
$smarty->assign("getplandetail", $getplandetail);



if($_SESSION['msg']){
		$smarty->assign("msg", $_SESSION['msg']);
		unset($_SESSION['msg']);
}

$active ="findjobs";
$smarty->assign('active',$active);

$smarty->display(TEMPLATEDIR.'/modules/jobs/findjobdetail.tpl');
unset($smarty);
?>
